<template>
  <el-card class="content">
    <el-row>
      <el-col :span="4">
        <span style="fontsize: 16px">尾矿库类型:</span>
        <el-select v-model="query.tailingTypeId" size="mini" clearable>
          <el-option
            v-for="item in isTailingList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-col>
      <el-col :span="6">
        <el-button class="black-button" @click="getSearch" size="small"
          >查询</el-button
        >
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="small"
          @click="dialogVisible = true"
          >新增</el-button
        >
      </el-col>
    </el-row>
    <p class="bg-purple">尾矿库信息列表</p>
    <el-table :data="tailingList" stripe size="small">
      <el-table-column
        prop="tailingName"
        label="尾矿库名称"
        align="center"
      ></el-table-column>
      <el-table-column
        v-if="none"
        prop="id"
        label="尾矿库名称7778"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="tailingNumber"
        label="尾矿库编号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="tailingTypeName"
        label="尾矿库类型"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="industryTypeName"
        label="行业"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="mineralsSpeciesName"
        label="矿种"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="onlineMonitoringSys"
        label="是否安装在线监测系统"
        align="center"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.onlineMonitoringSys == 0">是</span>
          <span v-if="scope.row.onlineMonitoringSys == 1">否</span>
        </template>
      </el-table-column>
      <el-table-column prop="top" label="是否头顶库" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.top == 0">是</span>
          <span v-if="scope.row.top == 1">否</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="securityOfficer"
        label="分管安全负责人"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="securityOfficerTel"
        label="分管安全负责人电话"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="ondutyTel"
        label="值班电话"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="latitude"
        label="纬度"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="longitude"
        label="经度"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="useDate"
        label="投入使用日期"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="useYear"
        label="设计服务年限"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" align="center" prop="id">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="editTailing(scope.row)"
            >修改</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="delTailingList(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-row type="flex" justify="end">
      <!-- <el-col :span="7"> -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.page"
        :page-sizes="[10, 15]"
        :page-size="query.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <!-- 新增弹窗 -->
      <el-dialog
        title="添加尾矿库信息"
        :visible.sync="dialogVisible"
        :width="dialogWidth"
      >
        <el-form
          :model="addListForm"
          ref="addListForm"
          label-width="120px"
          size="mini"
          :rules="rules"
        >
          <el-row>
            <el-form-item label="尾矿库名称" prop="tailingName">
              <el-input
                v-model="addListForm.tailingName"
                placeholder="请填写尾矿库名称"
              ></el-input>
            </el-form-item>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="尾矿库编号" size="mini" prop="tailingNumber">
                <el-input
                  v-model="addListForm.tailingNumber"
                  style="width: 180px"
                  placeholder="请填写尾矿库编号"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="尾矿库类型"
                label-width="180px"
                prop="tailingTypeId"
                size="mini"
              >
                <el-select
                  v-model="addListForm.tailingTypeId"
                  style="width：200px"
                  label-width="110px"
                >
                  <el-option
                    v-for="item in isTailingList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="矿种" size="mini" prop="mineralsSpeciesId">
                <el-select
                  v-model="addListForm.mineralsSpeciesId"
                  style="width: 180px"
                >
                  <el-option
                    v-for="item in isMinerals"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="12">
              <el-form-item
                label="行业"
                size="mini"
                label-width="180px"
                prop="industryTypeId"
              >
                <el-select
                  v-model="addListForm.industryTypeId"
                  label-width="100px"
                  style="width: 180px"
                >
                  <el-option
                    v-for="item in isIndustryList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
          </el-row>

          <el-row>
            <el-col :span="12"
              ><el-form-item
                label="运行状况"
                label-width="120px"
                prop="operatingStatusId"
              >
                <el-select
                  v-model="addListForm.operatingStatusId"
                  size="mini"
                  style="width: 180px"
                >
                  <el-option
                    v-for="item in isRunningState"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="12">
              <el-form-item
                label="值班电话"
                size="mini"
                label-width="180px"
                prop="ondutyTel"
              >
                <el-input
                  v-model="addListForm.ondutyTel"
                  style="width: 180px"
                  placeholder="请填写值班电话"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12"
              ><el-form-item
                label="经度"
                size="mini"
                label-width="120px"
                prop="longitude"
              >
                <el-input
                  v-model="addListForm.longitude"
                  style="width: 180px"
                  placeholder="请填写经度"
                ></el-input> </el-form-item
            ></el-col>
            <el-col :span="12"
              ><el-form-item
                label="纬度"
                size="mini"
                label-width="180px"
                prop="latitude"
              >
                <el-input
                  v-model="addListForm.latitude"
                  style="width: 180px"
                  placeholder="请填写纬度"
                ></el-input> </el-form-item
            ></el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item
                label="分管安全负责人"
                size="mini"
                prop="securityOfficer"
                label-width="120px"
              >
                <el-input
                  v-model="addListForm.securityOfficer"
                  style="width: 180px"
                  placeholder="请填写分管安全负责人"
                ></el-input> </el-form-item
            ></el-col>
            <el-col :span="12"
              ><el-form-item
                label="分管安全负责人电话"
                label-width="180px"
                size="mini"
                prop="securityOfficerTel"
              >
                <el-input
                  v-model="addListForm.securityOfficerTel"
                  style="width: 180px"
                  placeholder="请填写分管安全负责人电话"
                ></el-input> </el-form-item
            ></el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="是否头顶库" label-width="120px" prop="top">
                <el-radio-group v-model="addListForm.top">
                  <el-radio
                    v-for="item in topList"
                    :key="item.id"
                    :label="item.id"
                    >{{ item.name }}</el-radio
                  >
                </el-radio-group>
              </el-form-item></el-col
            >
            <el-col :span="12">
              <el-form-item
                label="是否安装在线监测系统"
                label-width="180px"
                prop="onlineMonitoringSys"
              >
                <el-radio-group v-model="addListForm.onlineMonitoringSys">
                  <el-radio
                    v-for="item in onlineMonitoringSysList"
                    :key="item.id"
                    :label="item.id"
                    >{{ item.name }}</el-radio
                  >
                </el-radio-group>
              </el-form-item></el-col
            >
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="投入使用日期" size="mini" prop="useDate">
                <el-date-picker
                  v-model="addListForm.useDate"
                  placeholder="选择日期时间"
                  style="width: 180px"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker></el-form-item
            ></el-col>
            <el-col :span="12"
              ><el-form-item
                label="设计服务年限"
                size="mini"
                label-width="180px"
                prop="useYear"
              >
                <el-input
                  v-model="addListForm.useYear"
                  type="number"
                  style="width: 180px"
                  onkeyup="value=value.replace(/[^\d]/g,'')"
                  placeholder="选择服务年限"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item class="buttonfrom">
            <el-button type="primary" @click="isdialogVisible">确 定</el-button>
            <el-button @click="closeDialogVisible">取 消</el-button>
            <!-- </span> -->
          </el-form-item>
        </el-form>
      </el-dialog>
      <!-- </el-col> -->
    </el-row>
    <!-- 修改弹窗 -->
    <el-dialog
      title="修改尾矿库信息"
      :visible.sync="editDialogVisible"
      :width="dialogWidth"
    >
      <el-form
        :model="editListForm"
        ref="editListForm"
        label-width="120px"
        size="mini"
        :rules="ruless"
      >
        <el-form-item label="尾矿库名称" prop="tailingName">
          <el-input
            v-model="editListForm.tailingName"
            placeholder="请填写尾矿库名称"
          ></el-input>
        </el-form-item>

        <el-row>
          <el-col :span="12">
            <el-form-item label="尾矿库编号" size="mini" prop="tailingNumber">
              <el-input
                v-model="editListForm.tailingNumber"
                style="width: 180px"
                placeholder="请填写尾矿库编号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="尾矿库类型"
              label-width="180px"
              prop="tailingTypeId"
            >
              <el-select v-model="editListForm.tailingTypeId" size="mini">
                <el-option
                  v-for="item in isTailingList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="矿种" size="mini" prop="mineralsSpeciesId">
              <el-select
                v-model="editListForm.mineralsSpeciesId"
                label-width="100px"
              >
                <el-option
                  v-for="item in isMinerals"
                  :key="item.id"
                  :value="item.id"
                  :label="item.name"
                ></el-option>
              </el-select> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item
              label="行业"
              size="mini"
              label-width="180px"
              prop="industryTypeId"
            >
              <el-select
                v-model="editListForm.industryTypeId"
                label-width="100px"
              >
                <el-option
                  v-for="item in isIndustryList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select> </el-form-item
          ></el-col>
        </el-row>

        <el-row>
          <el-col :span="12"
            ><el-form-item
              label="运行状况"
              label-width="120px"
              prop="operatingStatusId"
            >
              <el-select v-model="editListForm.operatingStatusId" size="mini">
                <el-option
                  v-for="item in isRunningState"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item
              label="值班电话"
              size="mini"
              label-width="180px"
              prop="ondutyTel"
            >
              <el-input
                v-model="editListForm.ondutyTel"
                style="width: 180px"
                placeholder="请填写值班电话"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12"
            ><el-form-item
              label="经度"
              size="mini"
              label-width="120px"
              prop="longitude"
            >
              <el-input
                v-model="editListForm.longitude"
                style="width: 180px"
                placeholder="请填写经度"
              ></el-input> </el-form-item
          ></el-col>
          <el-col :span="12"
            ><el-form-item
              label="纬度"
              size="mini"
              label-width="180px"
              prop="latitude"
            >
              <el-input
                v-model="editListForm.latitude"
                style="width: 180px"
                placeholder="请填写纬度"
              ></el-input> </el-form-item
          ></el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item
              label="分管安全负责人"
              size="mini"
              prop="securityOfficer"
              label-width="130px"
            >
              <el-input
                v-model="editListForm.securityOfficer"
                style="width: 180px"
                placeholder="请填写分管安全负责人"
              ></el-input> </el-form-item
          ></el-col>
          <el-col :span="12"
            ><el-form-item
              label="分管安全负责人电话"
              label-width="180px"
              size="mini"
              prop="securityOfficerTel"
            >
              <el-input
                v-model="editListForm.securityOfficerTel"
                style="width: 180px"
                placeholder="请填写分管安全负责人电话"
              ></el-input> </el-form-item
          ></el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="是否头顶库" label-width="120px" prop="top">
              <el-radio-group v-model="editListForm.top">
                <el-radio
                  v-for="item in topList"
                  :key="item.id"
                  :label="item.id"
                  >{{ item.name }}</el-radio
                >
              </el-radio-group>
            </el-form-item></el-col
          >
          <el-col :span="12">
            <el-form-item
              label="是否安装在线监测系统"
              label-width="180px"
              prop="onlineMonitoringSys"
            >
              <el-radio-group v-model="editListForm.onlineMonitoringSys">
                <el-radio
                  v-for="item in onlineMonitoringSysList"
                  :key="item.id"
                  :label="item.id"
                  >{{ item.name }}</el-radio
                >
              </el-radio-group>
            </el-form-item></el-col
          >
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="投入使用日期" size="mini" prop="useDate">
              <el-date-picker
                v-model="editListForm.useDate"
                placeholder="选择日期时间"
                style="width: 180px"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker> </el-form-item
          ></el-col>
          <el-col :span="12"
            ><el-form-item
              label="设计服务年限"
              size="mini"
              label-width="180px"
              prop="useYear"
            >
              <el-input
                v-model="editListForm.useYear"
                type="number"
                placeholder="选择服务年限"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item class="buttonfrom">
          <!-- <span slot="footer" class="dialog-footer"> -->
          <el-button type="primary" @click="EditdialogVisible">确 定</el-button>
          <el-button @click="eidtCloseDialogVisible">取 消</el-button>
          <!-- </span> -->
        </el-form-item>
      </el-form>
    </el-dialog>
  </el-card>
</template>

<script>
import {
  getTailingPondByPage,
  getIndustryTypeList,
  getMineralsSpeciesList,
  getOperatingStatusList,
  getTailingTypeList,
} from "../../../api/api";
import Axios from "axios";
export default {
  name: "VersionUpdateChild",
  data() {
    return {
      value1: "",
      value2: "",
      total: 1,
      dialogWidth: "750px",
      query: {
        page: 1,
        pagesize: 5,
        tailingTypeId: "",
      },
      tailingList: [],
      dialogVisible: false,
      addListForm: {
        tailingName: "",
        tailingNumber: null,
        tailingTypeId: null,
        mineralsSpeciesId: null,
        industryTypeId: null,
        operatingStatusId: null,
        ondutyTel: null,
        longitude: null,
        latitude: null,
        securityOfficer: "",
        securityOfficerTel: "",
        onlineMonitoringSys: "",
        top: null,
        useDate: "",
        useYear: "",
        unitId: sessionStorage.getItem("unitId"),
      },
      //表单验证
      rules: {
        tailingName: [
          { required: true, message: "请输入尾矿库名称", trigger: "blur" },
          { min: 0, max: 30, trigger: "blur" },
        ],
        minetailingNumberrals: [
          { required: true, message: "请输入尾矿库编号", trigger: "blur" },
        ],
        tailingTypeId: [
          { required: true, message: "请选择类型", trigger: "change" },
        ],
        mineralsSpeciesId: [
          { required: true, message: "请选择矿种", trigger: "change" },
        ],

        industryTypeId: [
          { required: true, message: "请选择行业", trigger: "change" },
        ],
        operatingStatusId: [
          { required: true, message: "请选择运行状况", trigger: "change" },
        ],
        ondutyTel: [
          { required: true, message: "请填写值班电话", trigger: "blur" },
        ],
        longitude: [{ required: true, message: "请填写经度", trigger: "blur" }],
        latitude: [{ required: true, message: "请填写纬度", trigger: "blur" }],
        securityOfficerTel: [
          { required: true, validator: this.checkPhone, trigger: "blur" },
        ],
        securityOfficer: [
          { required: true, message: "请填写分管安全负责人", trigger: "blur" },
        ],
        onlineMonitoringSys: [
          {
            required: true,
            message: "请选择是否安装在线监测系统",
            trigger: "change",
          },
        ],
        top: [
          {
            required: true,
            message: "请选择是否是否头顶库",
            trigger: "change",
          },
        ],
        useDate: [
          { required: true, message: "请选择投入使用日期", trigger: "change" },
        ],
        useYear: [
          { required: true, message: "请选择设计服务年限", trigger: "change" },
        ],
      },
      ruless: {
        tailingName: [
          { required: true, message: "请输入尾矿库名称", trigger: "blur" },
          { min: 0, max: 30, trigger: "blur" },
        ],
        minetailingNumberrals: [
          { required: true, message: "请输入尾矿库编号", trigger: "change" },
        ],
        tailingTypeId: [
          { required: true, message: "请选择类型", trigger: "change" },
        ],
        mineralsSpeciesId: [
          { required: true, message: "请选择矿种", trigger: "change" },
        ],

        industryTypeId: [
          { required: true, message: "请选择行业", trigger: "change" },
        ],
        operatingStatusId: [
          { required: true, message: "请选择运行状况", trigger: "change" },
        ],
        ondutyTel: [
          { required: true, message: "请填写值班电话", trigger: "blur" },
        ],
        longitude: [{ required: true, message: "请填写经度", trigger: "blur" }],
        latitude: [{ required: true, message: "请填写纬度", trigger: "blur" }],
        securityOfficerTel: [
          { required: true, validator: this.checkPhone, trigger: "blur" },
        ],
        securityOfficer: [
          { required: true, message: "请填写分管安全负责人", trigger: "blur" },
        ],
        onlineMonitoringSys: [
          {
            required: true,
            message: "请选择是否安装在线监测系统",
            trigger: "change",
          },
        ],
        top: [
          {
            required: true,
            message: "请选择是否是否头顶库",
            trigger: "change",
          },
        ],
        useDate: [
          { required: true, message: "请选择投入使用日期", trigger: "change" },
        ],
        useYear: [
          { required: true, message: "请选择设计服务年限", trigger: "change" },
        ],
      },
      //行业列表
      isIndustryList: [],
      isMinerals: [], //矿种
      isRunningState: [], //运行状况
      isTailingList: [], //类型列表
      topList: [
        { id: 0, name: "是" },
        { id: 1, name: "否" },
      ],
      onlineMonitoringSysList: [
        { id: 0, name: "是" },
        { id: 1, name: "否" },
      ],
      //修改弹窗
      editListForm: {
        tailingName: "",
        tailingNumber: null,
        tailingTypeId: null,
        mineralsSpeciesId: null,
        industryTypeId: null,
        operatingStatusId: null,
        ondutyTel: null,
        longitude: 116.397128,
        latitude: 39.916527,
        securityOfficer: "",
        securityOfficerTel: "",
        onlineMonitoringSys: "",
        top: null,
        useDate: "",
        useYear: "",
        unitId: "",
        id: null,
      },
      editDialogVisible: false,
      none: false,
    };
  },
  methods: {
    checkPhone(rule, value, callback) {
      if (!value) {
        return callback(new Error("不能为空"));
      } else {
        const reg = /^1[3|4|5|7|8|9][0-9]\d{8}$/;
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error("请输入正确的手机号"));
        }
      }
    },
    //分页修改
    async getTailingPage() {
      const res = await getTailingPondByPage({
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        tailingTypeId: this.query.tailingTypeId,
        unitId: sessionStorage.getItem("unitId"),
      });
      this.total = res.parameter.total;
      this.tailingList = res.parameter.list;
    },
    async getSearch() {
      const res = await getTailingPondByPage({
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        tailingTypeId: this.query.tailingTypeId,
        unitId: sessionStorage.getItem("unitId"),
      });
      if (res.resultCode == "204") {
        this.$message({
          message: "暂无数据",
          offset: 400,
          duration: 1000,
        });
        this.tailingList = [];
      }
      if (res.resultCode == "200") {
        this.$message({
          type: "success",
          message: "成功查询到数据",
          offset: 400,
          duration: 1000,
        });
        this.total = res.parameter.total;
        this.tailingList = res.parameter.list;
      }
      if (res.resultCode == "400") {
        this.$message({
          type: "error",
          message: "查询失败",
          offset: 400,
          duration: 1000,
        });
        this.tailingList = [];
      }
    },
    handleSizeChange(val) {
      this.query.pagesize = val;
      this.getTailingPage();
    },
    handleCurrentChange(val) {
      this.query.page = val;
      this.getTailingPage();
    },
    //行业列表
    async getIndustryList() {
      const res = await getIndustryTypeList();
      if (res.resultCode == "400")
        return this.$message({
          type: "error",
          message: "查询行业列表失败",
          offset: 400,
          duration: 1000,
        });
      res.parameter.forEach((item) => {
        if (item !== undefined) {
          this.isIndustryList.push(item);
        }
      });
    },
    //矿种
    async gettMineralsS() {
      const res = await getMineralsSpeciesList();
      if (res.resultCode == "400")
        return this.$message({
          type: "error",
          message: "查询矿种列表失败",
          offset: 400,
          duration: 1000,
        });
      res.parameter.forEach((item) => {
        if (item !== undefined) {
          this.isMinerals.push(item);
        }
      });
    },
    // 运行
    async getOperatingStatusList() {
      const res = await getOperatingStatusList();
      if (res.resultCode == "400")
        return this.$message({
          type: "error",
          message: "查询运行状态失败",
          offset: 400,
          duration: 1000,
        });
      res.parameter.forEach((item) => {
        if (item !== undefined) {
          this.isRunningState.push(item);
        }
      });
    },
    //列表类型
    async getTailingTypeList() {
      const res = await getTailingTypeList();
      if (res.resultCode == "400")
        return this.$message({
          type: "error",
          message: "查询尾矿库列表失败",
          offset: 400,
          duration: 1000,
        });
      res.parameter.forEach((item) => {
        if (item !== undefined) {
          this.isTailingList.push(item);
        }
      });
    },
    //添加尾矿库
    isdialogVisible() {
      this.$refs.addListForm.validate((val) => {
        if (val) {
          const formData = new FormData();
          for (const [key, value] of Object.entries(this.addListForm)) {
            formData.append(key, value);
          }
          Axios({
            method: "post",
            url: "/tailingPond/addTailingPond",
            data: formData,
          }).then((res) => {
            console.log(res);
            if (res.data.resultCode == "200") {
              this.getTailingPage();
              this.$message({
                type: "success",
                message: "新增成功",
                offset: 400,
                duration: 1000,
              });
            } else if (res.data.resultCode == "400") {
              this.$message({
                type: "error",
                message: "新增失败",
                offset: 400,
                duration: 1000,
              });
            }
          });
          this.dialogVisible = false;
        } else {
          this.$message({
            type: "error",
            message: "请完善表单信息",
            offset: 400,
            duration: 1000,
          });
        }
      });

      this.$refs.addListForm.resetFields();
    },
    // 取消
    closeDialogVisible() {
      this.$refs.addListForm.resetFields();
      this.dialogVisible = false;
    },
    //  删除尾矿库
    async delTailingList(id) {
      this.$confirm("此操作将永久删除此数据，确定要删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(() => {
        Axios({
          method: "get",
          url: "/tailingPond/deleteTailingPond/" + `${id}`,
        })
          .then((res) => {
            if (res.status == "200") {
              this.getTailingPage();
              this.$message({
                type: "success",
                message: "删除成功",
                offset: 400,
                duration: 1000,
              });
            } else {
              this.$message({
                type: "error",
                message: "删除失败",
                offset: 400,
                duration: 1000,
              });
            }
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
              offset: 400,
              duration: 1000,
            });
          });
      });
    },
    //确认修改
    async EditdialogVisible() {
      this.$refs.editListForm.validate((val) => {
        if (val) {
          const formData = new FormData();
          for (const [key, value] of Object.entries(this.editListForm)) {
            formData.append(key, value);
          }
          // console.log(formData);
          Axios({
            method: "post",
            url: "/tailingPond/updateTailingPond",
            data: formData,
          }).then((res) => {
            console.log(res);
            if (res.data.resultCode == "200") {
              // this.getTailingList()
              this.$message({
                type: "success",
                message: "修改成功",
                offset: 400,
                duration: 1000,
              });
              this.getTailingPage();
              this.editDialogVisible = false;
            } else {
              this.$message({
                type: "error",
                message: "修改失败",
                offset: 400,
                duration: 1000,
              });
            }
          });
        } else {
          this.$message({
            type: "error",
            message: "请完成表单",
            offset: 400,
            duration: 1000,
          });
        }
      });

      // })
    },
    eidtCloseDialogVisible() {
      this.editDialogVisible = false;
    },
    //修改弹窗弹出
    async editTailing(row) {
      console.log(row);
      // this.getIndustryList()
      this.editListForm.tailingName = row.tailingName;
      this.editListForm.tailingNumber = row.tailingNumber;
      this.editListForm.tailingTypeId = row.tailingTypeId;
      this.editListForm.mineralsSpeciesId = row.mineralsSpeciesId;
      this.editListForm.industryTypeId = row.industryTypeId;
      this.editListForm.operatingStatusId = row.operatingStatusId;
      this.editListForm.ondutyTel = row.ondutyTel;
      this.editListForm.longitude = row.longitude;
      this.editListForm.latitude = row.latitude;
      this.editListForm.securityOfficer = row.securityOfficer;
      this.editListForm.securityOfficerTel = row.securityOfficerTel;
      this.editListForm.onlineMonitoringSys = row.onlineMonitoringSys;
      this.editListForm.top = row.top;
      this.editListForm.useYear = row.useYear;
      this.editListForm.useDate = row.useDate;
      console.log(this.editListForm.useDate);
      this.editListForm.unitId = row.unitId;
      this.editListForm.id = row.id;
      this.editDialogVisible = true;
    },
    //弹出
    async seachTailiing() {
      this.getTailingPage();
      // const res = await getTailingPondByPage({ pageCount: this.query.page, pageSize: this.query.pagesize, tailingTypeId: this.query.tailingTypeId })
      // // this.tailingList = res.parameter.list
      // if (res.resultCode == '204') {
      //   this.tailingList = []
      //   this.query.tailingTypeId = undefined

      // } else {
      //   this.tailingList = res.parameter.list

      // }
      // this.total =res.parameter.total
    },
    setDialogWidth() {
      var val = document.body.clientWidth;
      const def = 750; // 默认宽度
      if (val < def) {
        this.dialogWidth = "100%";
      } else {
        this.dialogWidth = def + "px";
      }
    },
  },
  created() {},
  mounted() {
    this.getTailingPage(),
      this.getIndustryList(),
      this.gettMineralsS(),
      this.getOperatingStatusList(),
      this.getTailingTypeList(),
      (window.onresize = () => {
        return (() => {
          this.setDialogWidth();
        })();
      });
  },
};
</script>

<style scoped>
.content {
  height: 87vh;
  overflow: auto;
}
.el-button {
  font-size: 14px;
  margin-bottom: 8px;
}
.black-button {
  background-color: black;
  color: white;
}
.bg-purple {
  background: #d3dce6;
  height: 30px;
  font-size: 14px;
  line-height: 30px;
  padding-left: 10px;
}
.el-form-item {
  height: 45px !important;
}
.buttonfrom {
  margin-left: 200px;
  /* background: red; */
}
.none {
  display: none;
}
.el-table {
  display: block;
  height: 67.2vh;
  overflow-y: auto;
  margin-bottom: 15px;
}
.el-table::before {
  z-index: inherit;
}
</style>
